// 获取数据库中的省份信息   并插入到对应的下拉框中
function getProvincialName(itemIds) {
  let allProvince = "" ;
  $.getJSON("allProvince.do",function(data){
    for (let i = 0; i < data.length ; i ++){
      allProvince += `<option value="${data[i]}">${data[i]}</option>` ;
    }
    itemIds.forEach((e)=>{
      $(e).html(allProvince);
    })
  })
}


//获取 确诊 总数

function getCount() {
  $.getJSON('count.do', function (data) {
    $("#allcount").text(data + "人");
  });
}

// 各省治愈人数前五的地区
function getConfirmCount(provincialName) {
  drawingTableRequest('confirmCount.do?provincialName=' + provincialName, "confirmCount");
}
// 各省治愈人数前五的地区
function getCureCount(provincialName) {
  drawingTableRequest('cureCount.do?provincialName=' + provincialName, "cureCount");
}
// 各省死亡前五的地区
function getDeathCount(provincialName) {
  drawingTableRequest('deathCount.do?provincialName=' + provincialName, "deathCount");
}

// 抽离两个方法
function drawingTableRequest(url, drawId) {
  $.getJSON(url, function (data) {
    //遍历数据集
    let dataTitle = [];
    let dataAll = [];

    data.forEach((e) => {
      dataTitle.push(e["name"]);
      dataAll.push(e["value"]);
    })
    drawTableData(drawId, dataTitle, dataAll);
  });
}

function drawTableData(drawId, dataTitle, data) {
  let pie_fanzui = echarts.init(document.getElementById(drawId), 'infographic');
  option = {
    tooltip: {
      trigger: 'axis',
      axisPointer: {            // 坐标轴指示器，坐标轴触发有效
        type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
      }
    },
    grid: {
      left: 40,
      right: 20,
      top: 30,
      bottom: 0,
      containLabel: true
    },

    xAxis: {
      type: 'value',
      axisLine: {
        lineStyle: {
          color: 'rgba(255,255,255,0)'
        }
      },
      splitLine: {
        lineStyle: {
          color: 'rgba(255,255,255,0)'
        }
      },
      axisLabel: {
        color: "rgba(255,255,255,0)"
      },
      boundaryGap: [0, 0.01]
    },
    yAxis: {
      type: 'category',
      axisLine: {
        lineStyle: {
          color: 'rgba(255,255,255,5)'
        }
      },
      splitLine: {
        lineStyle: {
          color: 'rgba(255,255,255,1)'
        }
      },
      axisLabel: {
        color: "red"
      },
      data: dataTitle
    },
    series: [
      {
        name: '2011年',
        type: 'bar',
        barWidth: 20,
        itemStyle: {
          normal: {
            color: 'blue',
            opacity: 1,
            barBorderRadius: 5,
          }
        },
        data: data
      }
    ]
  };
  pie_fanzui.setOption(option);
}





